package org.dtrd.modules.achievement.entity.bean;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.dtrd.common.util.DateUtils;
import org.dtrd.modules.achievement.entity.po.DtrdEntRdSigninPlan;
import org.dtrd.modules.achievement.entity.po.DtrdEntRdSigninRecord;

import java.util.List;

@Data
@ApiModel(value = "打卡记录")
public class SigninRecord {

    @ApiModelProperty(value = "记录ID")
    private Integer dataId;

    private Integer patientId;

    private Integer doctorId;

    @ApiModelProperty(value = "记录日期,yyyy-MM-dd", example = "2021-09-21")
    private String recordDate;

    @ApiModelProperty(value = "打卡计划-JSON串")
    private String signInJson;

    @ApiModelProperty(value = "打卡计划-数组")
    private List<SignInAction> signInActionList;

    public void setSignInJson(String signInJson) {
        this.signInJson = signInJson;
        if (signInJson != null) {
            signInActionList = JSONObject.parseArray(signInJson, SignInAction.class);
        }
    }

    public SigninRecord fromPO(DtrdEntRdSigninRecord plan) {
        dataId = plan.getDataId();
        patientId = plan.getPatientId();
        doctorId = plan.getDoctorId();
        recordDate=DateUtils.formatDate(plan.getRecordDate());
        setSignInJson(plan.getSighInJson());
        return this;
    }

    @Override
    public String toString() {
        return "SigninRecord{" +
                "dataId=" + dataId +
                ", recordDate='" + recordDate + '\'' +
                ", signInActionList=" + signInActionList +
                '}';
    }
}